
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 店铺管理 >> 在线店铺列表</title>
	<script type="text/javascript" src="${base}/admin/js/jquery-1.7.min.js"></script>
	<link rel="stylesheet" href="${base}/admin/css/tableStyle.css" type="text/css"></link>
	<script type="text/javascript" src="${base}/admin/js/tableJs.js"></script>
	<style type="text/css">
		.sort{
			cursor: pointer;
			margin-right:20px;float:right;
		}
		.sort img{
			width:15px;
			margin:0 5px 0 0;
		}
	</style>
	
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="34" bgcolor="#353c44"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" valign="center">
                	<div align="center"><img src="images/tb.gif" width="14" height="14" /></div></td>
                <td width="44%" valign="center">
                	<span class="STYLE1">店铺管理&nbsp;>>&nbsp;在线店铺列表</span>
                </td>
                
              </tr>
            </table></td>
            <td>
            	<div align="right" style="width:200px;">
            	</div>
            </td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>
	    <table width="50%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce" onmouseover="changeto()" onmouseout="changeback()">
	      <form id="brandsForm" action="brandCategory_save_sort.action" >
	      <tr>
	        <th width="15%" class="columnTitle">
	        <span>分类名称</span>
	        <span> <input id="submit" type="button" value="保存" onclick="sort_submit()" style="display:none;float:right;"/></span><span class="clear"></span>
	        </th>
	      </tr>
	      <input type="hidden"/>
	      <#list brandCategoryList as category>     
	      <tr id="row${category_index}">
	      	<input type="checkbox"  name="ids" value="${category.id}" class="checkbox" checked="checked" style="display:none" />
	         <td class="cellContent">${(category.name)!''}
	         <div class="sort">
		         <img src="images/sort_up.ico" title="上移" onclick="javascript:sortUp(this,'${(category.id)!''}');"/>
		         <img src="images/sort_down.ico" title="下移" onclick="javascript:sortDown(this,'${(category.id)!''}');"/></div>
	         <div class="clear"></div>
	        </td>
	      </tr>
	      
	      </#list>
	      </form>
	      
	    </table>
   </td>
   
  </tr>
 </table>
 </td>
 </tr>
</table>


<script type="text/javascript">
	var ids=[
		<#list brandCategoryList as category> 
			'${(category.id)!''}',
		</#list>
	];	
	
	function sortUp(obj,id){
		var $row=$(obj).parent().parent().parent();
		var $prev=$row.prev("tr");
		if($prev.html()!=null){
			$prev.before($row);
			changeBgcolor(obj);
			var index=findIdIndex(id);
			var temp=ids[index-1];
			ids[index-1]=ids[index];
			ids[index]=temp;
			
			
		}
	}
			
	function sortDown(obj,id){
		var $row=$(obj).parent().parent().parent();
		var $next=$row.next("tr");
		if($next.html()!=null){
			$next.after($row);
			changeBgcolor(obj);
			var index=findIdIndex(id);
			var temp=ids[index+1];
			ids[index+1]=ids[index];
			ids[index]=temp;
			
			
		}
		
	}
	
	function changeBgcolor(obj){
		$(".cellContent").css("background-color","white");
		$(obj).parent().parent().css("background-color","#FFEFDB");
		$("#submit").show();
	}
	
	function findIdIndex(id){
		for(var index in ids){
		  if(ids[index]===id){
		  	return index*1;
		  }
		}
		alert(id);
		return -1;
	}
       
    function sort_submit(){
    	var str="";
    	for(var index in ids){
		  str+=ids[index]+",";
		}
    	$.post("brandCategory_save_sort.action",{"ids":str},function(data){
    			data=eval("("+data+")");
				if(data.status=="success"){
					alert(data.message);
					history.go(0);
					parent.category_left.history.go(0);
				}else{
					alert(data.message);
				}
    	});
    }
       
       
</script>

</body>
</html>